package com.gitee.faster.redis.command;

import com.gitee.faster.redis.protocol.RedisRequest;
import com.gitee.faster.redis.protocol.RedisResponse;
import com.gitee.faster.redis.storage.RedisDataStorage;
import redis.clients.jedis.Protocol;

import java.util.List;

/**
 * @author hongda.li
 */
public class ConfigCommand implements RedisCommand {
    @Override
    public Protocol.Command command() {
        return Protocol.Command.CONFIG;
    }

    @Override
    public List<Protocol.Keyword> keywords() {
        return List.of(Protocol.Keyword.GET);
    }

    @Override
    public RedisResponse execute(RedisRequest request, List<String> arguments) {
        Protocol.Keyword keyword = parseKeyword(arguments, 0);

        return switch (keyword) {
            case GET:
                yield RedisDataStorage.getInstance().query("config:" + arguments.get(1));
            default:
                yield RedisResponse.of("");
        };
    }
}
